import 'package:flutter_admin/utils/utils.dart';

class MpsTransit {
  String? id;
  String? createDateStart;
  String? createDateEnd;
  String? productName;
  String? defaultCode;
  String? description;
  String? uom;
  String? createDate;
  String? qtyTransit;
  String? qtyReceive;
  String? alreadyDone;

  MpsTransit({
    this.id,
    this.createDateStart,
    this.createDateEnd,
    this.productName,
    this.defaultCode,
    this.description,
    this.uom,
    this.createDate,
    this.qtyTransit,
    this.qtyReceive,
    this.alreadyDone,
  });

  MpsTransit copyWith({
    String? id,
  }) {
    return new MpsTransit(
      id: id ?? this.id,
    );
  }

  @override
  String toString() {
    return '''MpsTransit{
      id: id,
    }''';
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      (other is MpsTransit &&
          runtimeType == other.runtimeType &&
          id == other.id);

  factory MpsTransit.fromMap(Map<String, dynamic> map) {
    return new MpsTransit(
      id: map['id'] != false ? map['id'].toString() as String? : "",
      description: map['description'] != false
          ? map['description'].toString() as String?
          : "",
      createDate: map['create_date'] != false
          ? map['create_date'].toString() as String?
          : "",
      productName: map['product_name'] != false
          ? map['product_name'].toString() as String?
          : "",
      // productName: map['product_id'] != false
      //     ? map['product_id'][1].toString() as String?
      //     : "",
      defaultCode: map['default_code'] != false
          ? map['default_code'].toString() as String?
          : "",
      uom: map['uom_id'] != false ? map['uom_id'][1].toString() as String? : "",
      qtyReceive: map['qty_receive'] != false
          ? map['qty_receive'].toString() as String?
          : "",
      qtyTransit: map['qty_transit'] != false
          ? map['qty_transit'].toString() as String?
          : "",
      alreadyDone: map['already_done'] != false
          ? map['already_done'].toString() as String?
          : "",
    );
  }

  Map<String, dynamic> toMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
      'description': this.description,
      'createDate': this.createDate,
      'productName': this.productName,
      'defaultCode': this.defaultCode,
      'uom': this.uom,
      'qtyReceive': this.qtyReceive,
      'qtyTransit': this.qtyTransit,
      'alreadyDone': this.alreadyDone == 'true' ? '是' : '否',
    } as Map<String, dynamic>;
  }

  List toDomainList() {
    List list = [
      if (this.createDateStart != null && this.createDateStart != '')
        [
          'create_date',
          '>=',
          Utils.timeUTC(this.createDateStart! + " 00:00:00", isToBeijing: false)
        ],
      if (this.createDateEnd != null && this.createDateEnd != '')
        [
          'create_date',
          '<=',
          Utils.timeUTC(this.createDateEnd! + " 23:59:59", isToBeijing: false)
        ],
      if (this.productName != null && this.productName != '')
        ['product_name', 'like', '%${this.productName}%'],
      if (this.defaultCode != null && this.defaultCode != '')
        ['default_code', 'like', '%${this.defaultCode}%'],
      if (this.alreadyDone == 'true') ['already_done', '=', true],
      if (this.alreadyDone == 'false') ['already_done', '=', false],
    ] as List;
    // ignore: unnecessary_cast
    return list;
  }

  Map<String, dynamic> toOdooMap() {
    // ignore: unnecessary_cast
    return {
      'id': this.id,
    } as Map<String, dynamic>;
  }
}
